Ext.define('Admin.view.user.info.UserInfoForm', {
    extend: 'Ext.form.Panel',
    alias: 'widget.userInfoForm',
    xtype: 'userInfoForm',

    requires: [
        'Ext.form.field.Text',
        'Ext.form.field.File',
        'Ext.form.field.Date',
        'Ext.form.field.Radio',
        'Ext.button.Button'
    ],

    margin: '20',
    width: 450,

    controller: 'userInfoViewController',

    layout: 'column',

    items: [{
            xtype: 'container',
            defaultType: 'textfield',
            columnWidth: 0.5,
            layout: 'anchor',
            defaults: {
                anchor: '80%',
                margin: '0 0 20 0'
            },
            items: [{
                    xtype: 'container',
                    layout: {
                        type: 'hbox',
                        align: 'center',
                        pack: 'center'
                    },
                    anchor: '0',
                    margin: '0 0 30 0',
                    items: [{
                        xtype: 'image',
                        name: 'cover',
                        cls: 'cover-image',
                        height: 120,
                        width: 120,
                        alt: 'no user image',
                        listeners: {
                            afterrender: function() {
                                var data = Ext.util.JSON.decode(userInfo);
                                if (data.cover != null) {
                                    this.setSrc("upload/" + data.cover);
                                }
                            }
                        }
                    }, {
                        xtype: 'button',
                        text: '上传头像',
                        margin: '30',
                        width: 80,
                        name: 'cover-upload',
                        listeners: {
                            click: 'onCoverUploadClick'
                        }
                    }]
                },
                {
                    fieldLabel: '姓名',
                    name: 'fullname',
                    allowBlank: false,
                    blankText: '此项不能为空'
                },
                {
                    xtype: 'numberfield',
                    name: 'age',
                    fieldLabel: '年龄',
                    hideTrigger: true,
                    minValue: 16,
                    blankText: '此项不能为空'
                },
                {
                    xtype: 'fieldcontainer',
                    fieldLabel: '性别',
                    defaultType: 'radiofield',
                    allowBlank: false,
                    blankText: '此项不能为空',
                    layout: {
                        type: 'hbox',
                        align: 'stretch',
                        pack: 'start'
                    },
                    items: [{
                        id: 'infosex1',
                        boxLabel: '男',
                        name: 'sex',
                        inputValue: 'male'
                    }, {
                        id: 'infosex2',
                        boxLabel: '女',
                        name: 'sex',
                        inputValue: 'female',
                        margin: '0 0 0 15'
                    }]
                },
                {
                    fieldLabel: '联系电话',
                    name: 'phone',
                    allowBlank: false,
                    blankText: '此项不能为空',
                    regex: /^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8])|(19[7]))\d{8}$/,
                    regexText: '手机号码格式有错，例:136XXXXXXXX',
                },
                {
                    fieldLabel: '电子邮箱',
                    name: 'email',
                    vtype: 'email',
                    allowBlank: false,
                    blankText: '此项不能为空'
                }
            ]
        },
        {
            xtype: 'container',
            columnWidth: 0.5,
            layout: 'anchor',
            defaultType: 'textfield',
            defaults: {
                anchor: '80%',
                margin: '0 0 20 0'
            },
            items: [{
                    xtype: 'fieldcontainer',
                    height: 150,
                }, {
                    fieldLabel: '出生日期',
                    name: 'birthday',
                    xtype: 'datefield',
                    format: 'Y/m/d',
                    allowBlank: false,
                    blankText: '此项不能为空'
                }, {
                    xtype: 'combobox',
                    fieldLabel: '部门',
                    name: 'dept',
                    displayField: 'name',
                    valueField: 'id',
                    allowBlank: false,
                    blankText: '此项不能为空',
                    store: Ext.create('Admin.store.organization.OrganizationStore')
                },
                {
                    fieldLabel: '职位',
                    name: 'job',
                    allowBlank: false,
                    blankText: '此项不能为空'
                },
                {
                    fieldLabel: '入职日期',
                    name: 'enterTime',
                    xtype: 'datefield',
                    format: 'Y/m/d',
                    allowBlank: false,
                    blankText: '此项不能为空'
                },
                {
                    fieldLabel: '居住地址',
                    name: 'address',
                    allowBlank: false,
                    blankText: '此项不能为空'
                }
            ]
        }
    ],

    buttons: [{
        text: '取消更改',
        listeners: {
            click: 'onResetButton'
        }
    }, {
        text: '提交',
        formBind: true,
        ui: 'soft-green',
        listeners: {
            click: 'onSubmitButton'
        }
    }],

    listeners: {
        afterrender: function() {
            var form = this.getForm();
            var data = Ext.util.JSON.decode(userInfo);
            form.setValues(data);
            form.findField('dept').setValue(data.dept);
        }
    }

});